package com.yz.jdd.module.main;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.NumberPicker;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.CustomListener;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.TimePickerView;
import com.google.gson.Gson;
import com.yz.jdd.R;
import com.yz.jdd.base.activity.BaseActivity;
import com.yz.jdd.base.entity.Response_Base;
import com.yz.jdd.base.utils.BaseConfigs;
import com.yz.jdd.base.utils.Constants;
import com.yz.jdd.base.utils.DateUtils;
import com.yz.jdd.base.utils.LogUtils;
import com.yz.jdd.base.utils.PreferencesUtils;
import com.yz.jdd.base.utils.StringUtil;
import com.yz.jdd.module.main.adapter.FilterBusinessAdapter;
import com.yz.jdd.module.main.adapter.FilterSourseAdapter;
import com.yz.jdd.module.main.adapter.FilterStateAdapter;
import com.yz.jdd.module.main.adapter.FilterTypeAdapter;
import com.yz.jdd.module.main.entity.AccountInfoBean;
import com.yz.jdd.module.main.entity.FilterBean;
import com.yz.jdd.module.main.entity.FilterParams;
import com.yz.jdd.network.MySubscriber;
import com.yz.jdd.network.NetWorkRequset;
import com.yz.jdd.network.response.Response_OrderTranscationParm;

import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import androidx.annotation.Nullable;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * 订单筛选 19/01/26 jmliu
 */
public class FilterActivity extends BaseActivity {


    @BindView(R.id.top_back)
    TextView topBack;
    @BindView(R.id.top_title)
    TextView topTitle;
    @BindView(R.id.top_right)
    TextView topRight;

    @BindView(R.id.date_tv)
    TextView dateTv;
    @BindView(R.id.shop_range_tv)
    TextView shopTv;
    @BindView(R.id.reset_tv)
    TextView resetTv;
    @BindView(R.id.sure_tv)
    TextView sureTv;
    @BindView(R.id.paytype_gridview)
    GridView typeGridView;
    @BindView(R.id.orderstate_gridview)
    GridView stateGridView;
    @BindView(R.id.ordersource_gridview)
    GridView sourceGridView;
    @BindView(R.id.shop_range_layout)
    LinearLayout shop_rangeLayout;
    @BindView(R.id.filter_layout)
    RelativeLayout filter_layout;

    @BindView(R.id.business_gridview)
    GridView businessGridView;



    private FilterBusinessAdapter businessAdapter;
    private FilterTypeAdapter typeAdapter;
    private FilterStateAdapter stateAdapter;
    private FilterSourseAdapter sourceAdapter;


    private List<FilterBean.BizTypeBean> businessList;
    private List<FilterBean.PayTypeBean> typeList;
    private List<FilterBean.OrderStateBean> stateList;
    private List<FilterBean.OrderSourceBean> sourceList;


    private TimePickerView pvTime;


    @BindView(R.id.devices_range_tv)
    TextView devicesTv;
    @BindView(R.id.people_range_tv)
    TextView peopleTv;
    @BindView(R.id.layout_type)
    LinearLayout layoutType;
    @BindView(R.id.layout_other)
    LinearLayout layoutOther;

    //收银员筛选
    private TextView wireless_popup_yes;
    private TextView wireless_popup_no;
    private TextView wireless_popup_title;
    private PopupWindow wirelessPopupWindow;
    private NumberPicker numberPicker;
    View contentView;
    List<String> listStr;
    private int choosePosition = 0;  // 操作人选择

    private String dateRange;//日期查询时间
    private String createDate = "0";// 创建门店时间
    //是否为收银筛选
    private String isCashList;


    private String startDatePar;
    private String endDatePar;

    private String businessStr;
    private String orderType;
    private String typeStr;
    private String stateStr;
    private String sourceStr;

    private String shopIdPar;
    private String shopName;
    private String deviceName = "全部";
    private String deviceId = "";
    private String operatorName = "全部";
    private String operatorId = "";

    private FilterParams filterParams;
    Response_OrderTranscationParm responseOrderTranscationParm;

    private Date startTimeChoose;
    private String selectHint = "";

    //最大时间跨度31天 : (31 * 24 * 60 * 60 * 1000);
    private long maxSpan = 2678400000l;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_filter);
        ButterKnife.bind(this);
//        topTitle.setText("筛选");
        Bundle bundle = getIntent().getExtras();
        isCashList = bundle.getString("isCashList");
        topTitle.setText(isCashList);
        orderType = bundle.getString("orderType");
        if ("外卖订单".equals(isCashList)) {
            layoutType.setVisibility(View.GONE);
            layoutOther.setVisibility(View.GONE);
        }
//        订单页面传递过来的值
        filterParams = (FilterParams) getIntent().getSerializableExtra("filterParams");
        if (filterParams != null) {
            startDatePar = filterParams.getStartTime();
            endDatePar = filterParams.getEndTime();

            //  orderType = filterParams.getOrderType();
            businessStr=filterParams.getBizType();
            typeStr = filterParams.getPayType();
            stateStr = filterParams.getOrderStatus();
            sourceStr = filterParams.getOrderSource();

            shopIdPar = filterParams.getShopId();
            shopName = filterParams.getShopName();
            deviceName = filterParams.getDeviceName();
            deviceId = filterParams.getDeviceId();
            operatorName = filterParams.getOperatorName();
            operatorId = filterParams.getOperatorId();
        } else {
            filterParams = new FilterParams();
        }
        if (StringUtil.isEmpty(deviceName)) {
            devicesTv.setText("不限");
        } else {
            if ("全部".equals(deviceName)) {
                deviceId = "";
            }
            devicesTv.setText(deviceName);
        }

        if (StringUtil.isEmpty(operatorName)) {
            peopleTv.setText("不限");
        } else {
            if ("全部".equals(operatorName)) {
                operatorId = "";
            }
            peopleTv.setText(operatorName);
        }

        getDeviceSN();
        initDate();
        initSelect();
        if (PreferencesUtils.getString(FilterActivity.this, BaseConfigs.PREF_ROLE_TIME, "").isEmpty()) {
            getBossAccountTime();
        } else {
            createDate = PreferencesUtils.getString(FilterActivity.this, BaseConfigs.PREF_ROLE_TIME, "0");
        }
        if (!StringUtil.isBlank(shopIdPar)) {
            shopTv.setText(shopName);
        }
        if (StringUtil.isBlank(startDatePar)) {
            startDatePar = DateUtils.getOldDateYMD(0) + " 00:00";
        }
        if (StringUtil.isBlank(endDatePar)) {
            endDatePar = DateUtils.getOldDate(0);
        }
        dateTv.setText(startDatePar + " 至 " + endDatePar);

        if (PreferencesUtils.getString(FilterActivity.this, BaseConfigs.PREF_ROLE_ID, "").equals("4")) {
            shop_rangeLayout.setVisibility(View.GONE);
        }
        filterParams.setStartTime(startDatePar);
        filterParams.setEndTime(endDatePar);

        businessAdapter=new FilterBusinessAdapter(this,businessList);
        typeAdapter = new FilterTypeAdapter(this, typeList);
        stateAdapter = new FilterStateAdapter(this, stateList);
        sourceAdapter = new FilterSourseAdapter(this, sourceList);

        businessGridView.setSelector(new ColorDrawable(Color.TRANSPARENT));
        typeGridView.setSelector(new ColorDrawable(Color.TRANSPARENT));
        stateGridView.setSelector(new ColorDrawable(Color.TRANSPARENT));
        sourceGridView.setSelector(new ColorDrawable(Color.TRANSPARENT));

        if(businessList!=null){
            businessGridView.setAdapter(businessAdapter);
        }

        typeGridView.setAdapter(typeAdapter);
        stateGridView.setAdapter(stateAdapter);
        sourceGridView.setAdapter(sourceAdapter);

        businessGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                for (int j = 0; j < businessList.size(); j++) {
                    businessList.get(j).setSelect(false);
                }
                businessList.get(i).setSelect(true);
                businessAdapter.notifyDataSetChanged();
                businessStr = businessList.get(i).getId();
                filterParams.setBizType(businessStr);
            }
        });
        typeGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                for (int j = 0; j < typeList.size(); j++) {
                    typeList.get(j).setSelect(false);
                }
                typeList.get(i).setSelect(true);
                typeAdapter.notifyDataSetChanged();
                typeStr = typeList.get(i).getId();
                filterParams.setPayType(typeStr);
            }
        });
        stateGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                for (int j = 0; j < stateList.size(); j++) {
                    stateList.get(j).setSelect(false);
                }
                stateList.get(i).setSelect(true);
                stateAdapter.notifyDataSetChanged();
                stateStr = stateList.get(i).getId();
                filterParams.setOrderStatus(stateStr);
            }
        });
        sourceGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                for (int j = 0; j < sourceList.size(); j++) {
                    sourceList.get(j).setSelect(false);
                }
                sourceList.get(i).setSelect(true);
                sourceAdapter.notifyDataSetChanged();
                sourceStr = sourceList.get(i).getId();
                filterParams.setOrderSource(sourceStr);
            }
        });


    }

    @OnClick({R.id.top_back, R.id.sure_tv, R.id.reset_tv, R.id.shop_range_tv, R.id.date_tv, R.id.devices_range_tv, R.id.people_range_tv})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.top_back:
                finish();
                break;
            case R.id.date_tv:
                alertDatePicker("开始时间", startDatePar);
                break;
            case R.id.shop_range_tv: // 门店选择
                Intent intentC = new Intent(new Intent(FilterActivity.this, ChooseShopActivity.class));
                intentC.putExtra("shopId", shopIdPar);
                startActivityForResult(intentC, Constants.FilterActivityForResultCode);
                break;
            case R.id.devices_range_tv: // 设备选择
                Intent intentD = new Intent(new Intent(FilterActivity.this, ChooseDeviceSNActivity.class));
                intentD.putExtra("deviceName", deviceName);
                intentD.putExtra("deviceId", deviceId);
                startActivityForResult(intentD, Constants.FilterActivityForResultCode_2005);
                break;
            case R.id.people_range_tv: // 收银员选择
                String jsonStr = PreferencesUtils.getString(FilterActivity.this, BaseConfigs.STRING_ORDER_CONDITION_SN, "");
                if (!StringUtil.isEmpty(jsonStr)) {
                    responseOrderTranscationParm = new Gson().fromJson(jsonStr, Response_OrderTranscationParm.class);
                    listStr = new ArrayList<String>();
                    for (int i = 0; i < responseOrderTranscationParm.getOperatorIdList().size(); i++) {
                        listStr.add(responseOrderTranscationParm.getOperatorIdList().get(i).getOperatorName());
                    }
                    contentView = LayoutInflater.from(this).inflate(R.layout.popup_dishprintsetting_select, null, false);
                    wirelessPopupWindow = new PopupWindow(contentView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
                    numberPicker = (NumberPicker) contentView.findViewById(R.id.printer_popup_numberPicker);
                    wireless_popup_yes = (TextView) contentView.findViewById(R.id.printer_popup_yes);
                    wireless_popup_no = (TextView) contentView.findViewById(R.id.printer_popup_no);
                    wireless_popup_title = (TextView) contentView.findViewById(R.id.printer_popup_title);
                    setNumberPickerDividerColor(numberPicker);
                    wireless_popup_yes.setOnClickListener(onClickListener);
                    wireless_popup_no.setOnClickListener(onClickListener);
                    numberPicker.setFocusable(false);
                    numberPicker.setFocusableInTouchMode(false);
                    numberPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); // 关闭编辑模式
                    wirelessPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                    wirelessPopupWindow.setOutsideTouchable(true);
                    wirelessPopupWindow.setTouchable(true);
                    wirelessPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
                        @Override
                        public void onDismiss() {
                            WindowManager.LayoutParams lp = getWindow()
                                    .getAttributes();
                            lp.alpha = 1f;
                            getWindow().setAttributes(lp);
                        }
                    });
                    numberPicker.setMinValue(0);
                    numberPicker.setMaxValue(listStr.size() - 1);
                    numberPicker.setDisplayedValues(listStr.toArray(new String[listStr.size()]));
                    numberPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
                        @Override
                        public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
                            choosePosition = picker.getValue();
                            //   LogUtils.i("-------" + shoosePosition + "//////////" + listStr.get(shoosePosition));
                        }
                    });
                    try {
                        wirelessPopupWindow.showAtLocation(filter_layout, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
                    } catch (Exception e) {

                    }
                }
                break;
            case R.id.reset_tv:  // 重置

                for(int j = 0; j < businessList.size(); j++){
                    businessList.get(j).setSelect(false);
                }
                for (int j = 0; j < typeList.size(); j++) {
                    typeList.get(j).setSelect(false);
                }
                for (int j = 0; j < stateList.size(); j++) {
                    stateList.get(j).setSelect(false);
                }
                for (int j = 0; j < sourceList.size(); j++) {
                    sourceList.get(j).setSelect(false);
                }

                businessAdapter.notifyDataSetChanged();
                stateAdapter.notifyDataSetChanged();
                typeAdapter.notifyDataSetChanged();
                sourceAdapter.notifyDataSetChanged();

                peopleTv.setText("不限");
                devicesTv.setText("不限");

                deviceId = "";
                deviceName = "";
                operatorId = "";
                operatorName = "";

                businessStr="";
                sourceStr = "";
                typeStr = "";
                stateStr = "";
                shopIdPar = "";
                shopName = "";

                startDatePar = DateUtils.getOldDateYMD(0) + " 00:00";
                endDatePar = DateUtils.getOldDate(0);
                dateTv.setText(startDatePar + " 至 " + DateUtils.getOldDate(0));
                shopTv.setText("全部门店");
                filterParams = new FilterParams(startDatePar, DateUtils.getOldDate(0), "", "", "", "", "", "", "", "", "", "", "", "", "");
                filterParams.setBizType(businessStr);

                break;
            case R.id.sure_tv:
                if(TextUtils.isEmpty(startDatePar) || TextUtils.isEmpty(endDatePar)){
                    Toast.makeText(FilterActivity.this,"请输入完整的时间范围",Toast.LENGTH_SHORT).show();
                    return;
                }

                Intent intent = new Intent(FilterActivity.this, FilterOrderListActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("isCashList", isCashList);
                intent.putExtra("orderType", orderType); //订单类型
                if (filterParams != null) {
                    bundle.putSerializable("filterParams", filterParams);
                }

                intent.putExtras(bundle);
                startActivity(intent);
                finish();
                break;
        }
    }

    View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.printer_popup_yes:
                    peopleTv.setText(responseOrderTranscationParm.getOperatorIdList().get(choosePosition).getOperatorName());
                    operatorId = responseOrderTranscationParm.getOperatorIdList().get(choosePosition).getOperatorId();
                    operatorName = responseOrderTranscationParm.getOperatorIdList().get(choosePosition).getOperatorName();
                    filterParams.setOperatorId(operatorId);
                    filterParams.setOperatorName(operatorName);
                    wirelessPopupWindow.dismiss();

                    break;
                case R.id.printer_popup_no:
                    wirelessPopupWindow.dismiss();
                    break;
            }
        }
    };

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == Constants.FilterActivityForResultCode) {
            Bundle bundle = data.getExtras();
            shopIdPar = bundle.getString("shopId");
            shopName = bundle.getString("shopName");
            filterParams.setShopId(shopIdPar);
            filterParams.setShopName(shopName);
            if (!StringUtil.isBlank(shopIdPar) && !StringUtil.isBlank(shopName)) {
                shopTv.setText(bundle.getString("shopName"));
            } else {
                shopTv.setText("全部门店");
            }
        } else if (resultCode == Constants.FilterActivityForResultCode_2005) {
            Bundle bundle = data.getExtras();
            deviceId = bundle.getString("id");
            deviceName = bundle.getString("name");
            filterParams.setDeviceId(deviceId);
            filterParams.setDeviceName(deviceName);
            if ("全部".equals(deviceName)) {
                devicesTv.setText(deviceName);
                deviceId = "";
            } else {
                devicesTv.setText(deviceName + ":" + deviceId);
            }

        }
    }

    /**
     * 弹出日期选择
     */
    public void alertDatePicker(final String title, String selectTime) {
        boolean[] type = new boolean[]{
                true, true, true, false, false, false
        };
        // 用户上一次选择的时间
        final Calendar calendarSelect = Calendar.getInstance();
        calendarSelect.setTime(DateUtils.StringToDate(selectTime));

        final Calendar startDate = Calendar.getInstance();
        startDate.setTime(new Date());
        startDate.set(Calendar.MONTH, startDate.get(Calendar.MONTH) - 6);
//        LogUtils.i(startDate.getTimeInMillis() + " ---- 半年前的时间");
//        LogUtils.i( Long.parseLong(createDate) + " ---- 创建时间");
        //创建门店时间小于半年 ,则范围为创店时间
        if (startDate.getTimeInMillis() < Long.parseLong(createDate)) {
            Date dateShop = new Date(Long.parseLong(createDate));
            startDate.setTime(dateShop);
        }
        final Calendar endDate = Calendar.getInstance();
        endDate.set(endDate.get(Calendar.YEAR), endDate.get(Calendar.MONTH), endDate.get(Calendar.DATE), endDate.get(Calendar.HOUR_OF_DAY), endDate.get(Calendar.MINUTE)); //, endDate.get(Calendar.SECOND)
        pvTime = new TimePickerBuilder(FilterActivity.this, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {
                selectHint = "";
                String time = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(date);
                LogUtils.i(time + "///-------------" + title);
                if ("开始时间".equals(title)) {
                    if (date.getTime() > System.currentTimeMillis()) {
                        showToast("开始时间不能大于当前时间");
                        startTimeChoose = date;
                        selectHint = "开始";
                    } else {
                        dateRange = time;
                        dateTv.setText(dateRange);
                        startDatePar = time;
                        endDatePar = "";
                        filterParams.setStartTime(startDatePar);
                        //filterParams.setEndTime("");
                        startTimeChoose = date;
                        //默认结束时间为最长31天
                        long newStamp = date.getTime() + maxSpan - 1;
                        if (newStamp > System.currentTimeMillis()) {
                            newStamp = System.currentTimeMillis();
                        }
                        filterParams.setEndTime(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date(newStamp)));
                    }
                } else {
                    if (date.getTime() < startTimeChoose.getTime()) {
                        showToast("开始时间需小于结束时间");
                        selectHint = "结束";
                    } else if ((date.getTime() - startTimeChoose.getTime()) > (maxSpan - 1)) {
                        showToast("时间跨度不可超过31天");
                        selectHint = "结束";
                    } else {
                        dateRange = dateRange + " 至 " + time;
                        dateTv.setText(dateRange);
                        endDatePar = time;
                        filterParams.setEndTime(endDatePar);
                    }

                }
            }
        }).setType(type)
//                .setCancelText("取消1")//取消按钮文字
//                 .setSubmitText("确定2")//确认按钮文字
//                .setTitleText(title)
                .setRangDate(startDate, endDate)
                .setDate(calendarSelect)
                .setLayoutRes(R.layout.pickerview_custom_time, new CustomListener() {
                    @Override
                    public void customLayout(View view) {
                        final TextView tvSubmit = (TextView) view.findViewById(R.id.tv_finish);
                        final TextView tvCancel = (TextView) view.findViewById(R.id.tv_cancel);
                        final TextView tvTitle = (TextView) view.findViewById(R.id.tv_title);
                        tvTitle.setText(title);
                        tvSubmit.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                pvTime.returnData();
                                pvTime.dismiss();
                                LogUtils.i("vtvSubmit///jmliu");
                                if (selectHint.equals("开始")) {
                                    alertDatePicker("开始时间", startDatePar);
                                } else if (selectHint.equals("结束")) {
                                    alertDatePicker("结束时间", endDatePar);
                                } else {
                                    if ("开始时间".equals(title)) {
                                        alertDatePicker("结束时间", endDatePar);
                                    }
                                }
                                selectHint = "";
                            }
                        });
                        tvCancel.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                pvTime.dismiss();
                                LogUtils.i("tvCancel///jmliu");
                            }
                        });
                    }
                }) // 新加自定义布局
                .setContentTextSize(15)
                .setType(new boolean[]{true, true, true, true, true, false})
                .setLabel("年", "月", "日", "时", "分", "秒") //, "秒"
                .setLineSpacingMultiplier(1.2f) //1.2
                .setTextXOffset(0, 0, 0, 0, 0, 0)
                .isCenterLabel(false) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
                .setDividerColor(Color.parseColor("#EEEEEE"))
                .setOutSideCancelable(false)
                .build();
        pvTime.show();
    }

    private void getBossAccountTime() {
        try {
            NetWorkRequset.doBossAccountTime(new MySubscriber() {
                @Override
                public void onSuccess(Response_Base response_baseModel) {
                    if (response_baseModel.getResultObject() != null) {
                        LogUtils.i(response_baseModel.getResultObject().toString());
                        AccountInfoBean userInfoBean = (AccountInfoBean) response_baseModel.getResultObject();
                        createDate = userInfoBean.getCreateTime();
                        PreferencesUtils.putString(FilterActivity.this, BaseConfigs.PREF_ROLE_TIME, createDate);
                    }
                }

                @Override
                public void onNeedLogin(String msg) {

                }

                @Override
                public void onFail(Response_Base response_baseModel) {
                    showToastDialog(response_baseModel.getMsg());
                }
            });
        } catch (Exception e) {
            //  LogUtils.i("exception" + e.toString());
            showToastDialog("系统异常");
        }
    }

    public void initSelect() {
        if (!StringUtil.isBlank(businessStr)) {
            for (int i = 0; i < businessList.size(); i++) {
                if (businessList.get(i).getId().equals(businessStr)) {
                    businessList.get(i).setSelect(true);
                }
            }
        }
        if (!StringUtil.isBlank(typeStr)) {
            for (int i = 0; i < typeList.size(); i++) {
                if (typeList.get(i).getId().equals(typeStr)) {
                    typeList.get(i).setSelect(true);
                }
            }
        }
        if (!StringUtil.isBlank(stateStr)) {
            for (int i = 0; i < stateList.size(); i++) {
                if (stateList.get(i).getId().equals(stateStr)) {
                    stateList.get(i).setSelect(true);
                }
            }
        }
        if (!StringUtil.isBlank(sourceStr)) {
            for (int i = 0; i < sourceList.size(); i++) {
                if (sourceList.get(i).getId().equals(sourceStr)) {
                    sourceList.get(i).setSelect(true);
                }
            }
        }
    }

    public void initDate() {
        String jsonStr = PreferencesUtils.getString(FilterActivity.this, BaseConfigs.STRING_ORDER_CONDITION, "");
        if (!StringUtil.isEmpty(jsonStr)) {
            FilterBean filterBean = new Gson().fromJson(jsonStr, FilterBean.class);
            businessList=filterBean.getBizType();

            typeList = filterBean.getPayType();
            //收银订单只展示已收款/已退款
            stateList = new ArrayList<>();
            for (int i = 0; i < filterBean.getOrderState().size(); i++) {
                if ("异常订单".equals(isCashList) && filterBean.getOrderState().get(i).getType().equals("1")) {
                    stateList.add(filterBean.getOrderState().get(i));
                } else if (!"异常订单".equals(isCashList) && filterBean.getOrderState().get(i).getType().equals("0")) {
                    stateList.add(filterBean.getOrderState().get(i));
                }
            }
            sourceList = filterBean.getOrderSource();
        }
    }

    /**
     * 自定义滚动框分隔线颜色
     */
    private void setNumberPickerDividerColor(NumberPicker number) {
        Field[] pickerFields = NumberPicker.class.getDeclaredFields();
        for (Field pf : pickerFields) {
            if (pf.getName().equals("mSelectionDivider")) {
                pf.setAccessible(true);
                try {
                    //设置分割线的颜色值
                    pf.set(number, new ColorDrawable(Color.parseColor("#ffffff")));
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
            }
        }
    }

    /**
     * 获取设备sn/码id/收银员
     */
    public void getDeviceSN() {
        Map<String, String> params = new HashMap<>();
        String shopIdTemp = PreferencesUtils.getString(FilterActivity.this, BaseConfigs.PREF_SHOPID);
        if (!StringUtil.isEmpty(shopIdTemp)) {
            params.put("shopId", shopIdTemp);
        }
        NetWorkRequset.doGetOrderTranscationParam(new MySubscriber() {
            @Override
            public void onSuccess(Response_Base response_baseModel) {
                LogUtils.iLong("response_baseModel  ; " + response_baseModel.toString());
                if (response_baseModel.getResultObject() != null) {
                    LogUtils.iLong(response_baseModel.getResultObject().toString());
                    String json = new Gson().toJson(response_baseModel.getResultObject());
                    PreferencesUtils.putString(FilterActivity.this, BaseConfigs.STRING_ORDER_CONDITION_SN, json);
                }
            }

            @Override
            public void onNeedLogin(String msg) {

            }

            @Override
            public void onFail(Response_Base response_baseModel) {
                showToastDialog(response_baseModel.getMsg());
            }
        }, params);
    }
}
